package com.hmall.pay.pojo;

import com.hmall.common.dto.Item;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Data
public class ItemDoc {
    private Long id;//商品id 1
    private String name;//商品名称1
    private Long price;//价格（分）1
    private String image;//商品图片1
    private String category;//分类名称1
    private String brand;//品牌名称1
    private Integer sold;//销量1
    private Integer commentCount;//评论数1
    private Boolean isAD;// 是否是广告
    private List<String> suggestion;

    public ItemDoc() {
    }
    public ItemDoc(Item item) {
        this.brand=item.getBrand();
        this.category=item.getCategory();
        this.commentCount=item.getCommentCount();
        this.id=item.getId();
        this.image=item.getImage();
        this.isAD=item.getIsAD();
        this.name=item.getName();
        this.price=item.getPrice();
        this.sold=item.getSold();
        this.isAD=item.getIsAD();
        // 组装suggestion
        if(this.name.contains(" ")){
            // business有多个值，需要切割
            String[] arr = this.name.split(" ");
            // 添加元素
            this.suggestion = new ArrayList<>();
            this.suggestion.add(this.brand);
            this.suggestion.add(this.category);
            Collections.addAll(this.suggestion, arr);
        }else {
            this.suggestion = Arrays.asList(this.brand, this.name,this.category);
        }

    }

}